import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:ty_smart_watch/bean/sport_desc_bean.dart';

import '../controller/sport_controller.dart';

class DataGrid extends StatelessWidget {
  SportController sportController = Get.find();

  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.black,
      margin: const EdgeInsets.fromLTRB(10, 10, 10, 10),
      child: Obx(
        () => GridView.builder(
          shrinkWrap: true,
          physics: const NeverScrollableScrollPhysics(),
          gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
              crossAxisCount: 2, childAspectRatio: 3, mainAxisSpacing: 0.2, crossAxisSpacing: 0.2),
          itemCount: sportController.sportDetailGridList.value.length,
          itemBuilder: (BuildContext context, int index) {
            return DataItem(desc: sportController.sportDetailGridList.value[index]);
          },
        ),
      ),
    );
  }
}

class DataItem extends StatelessWidget {
  final SportDescBean desc;

  const DataItem({super.key, required this.desc});

  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.white,
      child: Row(
        children: [
          SizedBox(width: 10),
          Image.asset(desc.icon, width: 30, height: 30),
          SizedBox(width: 10),
          Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Text(desc.desc),
              Row(
                children: [
                  Text(desc.data, style: TextStyle(fontSize: 18)),
                  SizedBox(width: 4),
                  Text(desc.unit, style: TextStyle(fontSize: 8)),
                ],
              )
            ],
          )
        ],
      ),
    );
  }
}
